/**
 * @file RecordType.h
 * @author 严一涵 (yyhhenry@foxmail.com)
 * @brief 借阅记录类型
 * @version 0.1
 * @date 2022-05-14
 *
 * @copyright Copyright (c) 2022
 *
 */
#ifndef RECORDTYPE_H_YYH
#define RECORDTYPE_H_YYH
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "./StrFunc.h"
#include "./ListType.h"
#include "./AccountType.h"
#include "./BookType.h"
#include "./DateType.h"

/**
 * @brief 借阅记录类型
 * @author 严一涵
 */
typedef struct RecordType
{
    /**
     * @brief 图书编码
     *
     */
    char *bookId;
    /**
     * @brief 借阅人编码
     *
     */
    char *userId;
    /**
     * @brief 借阅日期
     *
     */
    char *startDate;
    /**
     * @brief 归还日期
     *
     */
    char *endDate;
} RecordType;

/**
 * @brief RecordType构造
 * @author 严一涵
 * @param str CSV格式的一行字符串
 */
RecordType *RecordType_RecordType(const char *str);

/**
 * @brief 链表对RecordType的支持
 * @author 严一涵
 */
RecordType *RecordType_ListNode(ListNode *p);

/**
 * @brief RecordType转为CSVStr
 * @author 严一涵
 */
char *RecordType_toCSVStr(RecordType *record);

/**
 * @brief AccountType销毁
 * @author 严一涵
 */
void RecordType_free(void *_record);

/**
 * @brief RecordListType绑定一个文件的账户链表
 * @author 严一涵
 */
typedef struct RecordListType
{
    char *filename;
    ListType *list;
} RecordListType;

const char *const RecordSheetTitle;

/**
 * @brief 给定文件名并生成RecordSheetTitle，默认调用一次read
 * @author 严一涵
 * @param _filename 文件名
 */
RecordListType *RecordListType_RecordListType(const char *_filename);

/**
 * @brief RecordListType销毁
 * @author 严一涵
 * @param recordList 所有权销毁，禁止外部使用
 */
void RecordListType_free(RecordListType *recordList);

/**
 * @brief RecordListType文件读入
 * @author 严一涵
 */
void RecordListType_read(RecordListType *recordList);

/**
 * @brief RecordListType文件写入
 * @author 严一涵
 */
void RecordListType_write(RecordListType *recordList);

/**
 * @brief 借阅人查询
 * @author 严一涵
 */
ListType *RecordListType_queryUser(RecordListType *recordList, const char *userId);

/**
 * @brief 唯一查询
 * @author 严一涵
 */
ListNode *RecordListType_query(RecordListType *recordList, const char *bookId, const char *userId);

/**
 * @brief 借书，需要保证操作可行
 * @author 严一涵
 */
void RecordListType_borrow(RecordListType *recordList, BookListType *bookList, AccountListType *accountList, const char *bookId, const char *userId);

/**
 * @brief 还书，需要保证操作可行
 * @author 严一涵
 */
void RecordListType_return(RecordListType *recordList, BookListType *bookList, AccountListType *accountList, const char *bookId, const char *userId);

/**
 * @brief 续借，需要保证操作可行
 * @author 严一涵
 */
void RecordListType_continue(RecordListType *recordList, BookListType *bookList, AccountListType *accountList, const char *bookId, const char *userId);

#endif // RECORDTYPE_H_YYH
